package com.cac.demo.newCode.sorting.service.Impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.cac.demo.controller.dispatchSearch.MsDeliveryPackageInfoRest;
import com.cac.demo.dao.msConsole.MsConsoleDao;
import com.cac.demo.newCode.cemop.dto.*;
import com.cac.demo.newCode.cemop.service.CemopService;
import com.cac.demo.newCode.cemop.service.Impl.CemopServiceImpl;
import com.cac.demo.newCode.cemop.utils.CemopXmlUtil;
import com.cac.demo.newCode.materialStorage.mapper.MsWorkbinMaterialMapper;
import com.cac.demo.newCode.materialStorage.mapper.WmsItemInventoryMapper;
import com.cac.demo.newCode.sorting.dto.StockDTO;
import com.cac.demo.newCode.sorting.dto.usableWorkbinDTO;
import com.cac.demo.newCode.sorting.entity.*;
import com.cac.demo.newCode.sorting.mapper.*;
import com.cac.demo.newCode.sorting.service.*;
import com.cac.demo.newCode.standardAssort.mapper.MsAoBzjBillMapper;
import com.cac.demo.newCode.standardAssort.vo.MsAoBzjBillVO;
import com.cac.demo.newCode.standardAssort.vo.WmsItemInventoryVO;
import com.cac.demo.service.gkinterface.WorkService;
import com.cac.demo.service.pointPackageSort.PointPackageSortService;
import com.cac.demo.util.XmlReadUtil;
import com.cac.demo.util.adapter.ComUtil;
import com.cac.demo.util.adapter.ResponseMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@Service
public class AoMatchPlanServiceImpl implements AoMatchPlanService {

    @Resource
    private IMsAoMatchInfoNewService imsAoMatchInfoService;
    @Resource
    private IMsSortItemInventoryTempService imsSortItemInventoryTempService;
    @Resource
    private MsTaskAoMapper msTaskAoMapper;
    @Resource
    private IMsTaskPackageService iMsTaskPackageService;
    @Resource
    private IMsTaskAoService iMsTaskAoService;
    @Resource
    private MsAoMatchBillMapper msAoMatchBillMapper;
    @Resource
    private MsAoMatchInfoMapper msAoMatchInfoMapper;
    @Resource
    private MsConsoleDao msConsoleDao;
    @Resource
    private MsDeliveryPackageInfoRest msDeliveryPackageInfoRest;
    @Resource
    private MsWorkbinMaterialMapper msWorkbinMaterialMapper;
    @Resource
    private MsSortItemInventoryTempMapper msSortItemInventoryTempMapper;
    @Resource
    private WmsItemInventoryMapper wmsItemInventoryMapper;
    @Resource
    PointPackageSortService pointPackageSortService;

    @Resource
    private MsAoBzjBillMapper msAoBzjBillMapper;
    @Autowired
    private WorkService workService;
    //xml文件处理
    @Resource
    private CemopXmlUtil cemopXmlUtil;
    @Resource
    private MsTaskPackageMapper msTaskPackageMapper;
    @Resource
    private WmsInvOutBillHMapper wmsInvOutBillHMapper;
    @Resource
    private WmsInvOutBillLMapper wmsInvOutBillLMapper;
    @Resource
    private CemopService cemopService;
    @Resource
    private MsTaskPackageChangeMapper msTaskPackageChangeMapper;
    @Resource
    private CemopServiceImpl cemopServiceImpl;


    @Transactional
    @Override
    public ResponseMsg<Object> AoMonthPlan(@RequestBody JSONObject jsonObject) {
        System.out.println("=========================Cemop月计划下发===========================" + jsonObject);
        try {
            //解压文件
            String fileUrl = jsonObject.get("fileUrl").toString();
            List<File> files = cemopXmlUtil.downloadAndExtractXMLFiles(fileUrl);
            //解析xml文件，拿到月计划内容（工作包、AO、物料）
            FileInputStream fileInputStream = new FileInputStream(files.get(0));
            XmlReadUtil xmlReadUtil = new XmlReadUtil(fileInputStream);
            List<Map<String, String>> list1 = xmlReadUtil.getAttributesByTagName("MOM_ASS_WORKPACKAGE_PLAN");
            List<Map<String, String>> list2 = xmlReadUtil.getAttributesByTagName("MOM_ASS_AOTASK");
            List<Map<String, String>> list3 = xmlReadUtil.getAttributesByTagName("MOM_ASS_SETOUT_MATERIAL");
            List<MomAssWorkPackagePlanDTO> momAssWorkPackagePlanDTOS = new ArrayList<>();
            List<MomAssAOTaskDTO> momAssAOTaskDTOS = new ArrayList<>();
            List<MomAssSetoutMaterialDTO> momAssSetoutMaterialDTOS = new ArrayList<>();
            for (Map<String, String> map : list1) {
                MomAssWorkPackagePlanDTO momAssWorkPackagePlanDTO = new MomAssWorkPackagePlanDTO();
                xmlReadUtil.mapToDTO(map, momAssWorkPackagePlanDTO);
                momAssWorkPackagePlanDTOS.add(momAssWorkPackagePlanDTO);
            }
            for (Map<String, String> map : list2) {
                MomAssAOTaskDTO momAssAOTaskDTO = new MomAssAOTaskDTO();
                xmlReadUtil.mapToDTO(map, momAssAOTaskDTO);
                momAssAOTaskDTOS.add(momAssAOTaskDTO);
            }
            for (Map<String, String> map : list3) {
                MomAssSetoutMaterialDTO momAssSetoutMaterialDTO = new MomAssSetoutMaterialDTO();
                xmlReadUtil.mapToDTO(map, momAssSetoutMaterialDTO);
                momAssSetoutMaterialDTOS.add(momAssSetoutMaterialDTO);
            }
            String groupNo = ComUtil.getId();
            //循环插入工作包
            for (MomAssWorkPackagePlanDTO momAssWorkPackagePlanDTO : momAssWorkPackagePlanDTOS) {
                MsTaskPackage msTaskPackage = new MsTaskPackage();
                msTaskPackage.setMsTaskPackageId(momAssWorkPackagePlanDTO.getMOM_ASS_WORKPACKAGE_PLAN_ID());
                msTaskPackage.setProductCode(momAssWorkPackagePlanDTO.getMODLS_ECD());
                msTaskPackage.setProductName(momAssWorkPackagePlanDTO.getMODLS_NAME());
                msTaskPackage.setBatchNo(momAssWorkPackagePlanDTO.getBCH_NO());
                msTaskPackage.setStartPlaneNo(momAssWorkPackagePlanDTO.getSORTIE_NO());
                msTaskPackage.setEndPlaneNo(momAssWorkPackagePlanDTO.getSORTIE_NO());
                msTaskPackage.setDepartCode(momAssWorkPackagePlanDTO.getMANUFA_BCPLT_ECD());
                msTaskPackage.setWorkPackageCode(momAssWorkPackagePlanDTO.getWORKPACKAGE_CODE());
                msTaskPackage.setPackageCode(momAssWorkPackagePlanDTO.getWORKPACKAGE_CODE());
                msTaskPackage.setPackageName(momAssWorkPackagePlanDTO.getWORKPACKAGE_NAME());
                msTaskPackage.setState("00");
                msTaskPackage.setAState("00");
                msTaskPackage.setCreatedBy(momAssWorkPackagePlanDTO.getPUBLISH_EMP());
                msTaskPackage.setCreationDate(new Date());
                msTaskPackage.setPlanStartDate(momAssWorkPackagePlanDTO.getPLAN_START_DATE());
                msTaskPackage.setPlanEndDate(momAssWorkPackagePlanDTO.getPLAN_END_DATE());
                msTaskPackage.setSortingStatus("00");
                msTaskPackage.setDeliveryState("00");
                msTaskPackage.setWeekTime(momAssWorkPackagePlanDTO.getBELONG_WEEK());
                msTaskPackage.setDailyTime(momAssWorkPackagePlanDTO.getBELONG_DAY());
                msTaskPackage.setImportGroupNo(groupNo);
                msTaskPackageMapper.insert(msTaskPackage);
            }
            //新增AO分拣任务
            for (MomAssAOTaskDTO momAssAOTask : momAssAOTaskDTOS) {
                WmsInvOutBillH wmsInvOutBillH = new WmsInvOutBillH();
                wmsInvOutBillH.setWmsInvOutBillHId(momAssAOTask.getMOM_ASS_AOTASK_ID());
                wmsInvOutBillH.setProductCode(momAssAOTask.getMODLS_ECD());
                wmsInvOutBillH.setBatchNo(momAssAOTask.getBCH_NO());
                wmsInvOutBillH.setStartLotNo(momAssAOTask.getSORTIE_NO());
                wmsInvOutBillH.setAoNo(momAssAOTask.getAO_NO());
                wmsInvOutBillHMapper.insert(wmsInvOutBillH);
                //修改工作包站位
                UpdateWrapper<MsTaskPackage> updateWrapper = new UpdateWrapper<>();
                updateWrapper.set("made_center",momAssAOTask.getSYS_MADE_CENTER());
                updateWrapper.eq("import_group_no",groupNo);
//                updateWrapper.eq("package_code",momAssAOTask.getWORKPACKAGE_CODE());
                if (momAssAOTask.getSYS_MADE_CENTER()!=null && momAssAOTask.getSYS_MADE_CENTER().length() > 0)
                {
                    iMsTaskPackageService.update(updateWrapper);
                }
                List<MomAssWorkPackagePlanDTO> collect = momAssWorkPackagePlanDTOS.stream().filter(momAssWorkPackagePlanDTO -> momAssWorkPackagePlanDTO.getWORKPACKAGE_CODE().equals(momAssAOTask.getWORKPACKAGE_CODE())).collect(Collectors.toList());
                String momAssWorkpackagePlanId = collect.get(0).getMOM_ASS_WORKPACKAGE_PLAN_ID();
                //插入AO信息
                MsTaskAo msTaskAo = new MsTaskAo();
                msTaskAo.setMsTaskAoId(momAssAOTask.getMOM_ASS_AOTASK_ID());
                msTaskAo.setProductCode(momAssAOTask.getMODLS_ECD());
                msTaskAo.setBatchNo(momAssAOTask.getBCH_NO());
                msTaskAo.setPlanId(momAssAOTask.getPLAN_ID());
                msTaskAo.setStartPlaneNo(momAssAOTask.getSORTIE_NO());
                msTaskAo.setDepartCode(momAssAOTask.getMANUFA_BCPLT_ECD());
                msTaskAo.setPackageCode(momAssAOTask.getWORKPACKAGE_CODE());
                msTaskAo.setMsTaskPackageId(momAssWorkpackagePlanId);
                msTaskAo.setAoCode(momAssAOTask.getAO_NO());
                msTaskAo.setAoName(momAssAOTask.getAO_NAME());
                msTaskAo.setRequiredTime(momAssAOTask.getPLAN_START_DATE());
                msTaskAo.setState("00");
                msTaskAo.setAState("00");
                msTaskAo.setCreatedBy(momAssAOTask.getCREATED_BY());
                msTaskAo.setCreationDate(new Date());
                msTaskAo.setLastUpdatedBy(momAssAOTask.getLAST_UPDATED_BY());
                msTaskAo.setLastUpdateDate(momAssAOTask.getLAST_UPDATE_DATE());
                if (momAssAOTask.getLAST_UPDATE_IP().isEmpty())
                {
                    msTaskAo.setLastUpdateIp(momAssAOTask.getLAST_UPDATE_IP());
                }
                msTaskAo.setImportGroupNo(groupNo);
                msTaskAo.setSortingStatus("00");
                msTaskAo.setStation(momAssAOTask.getSYS_MADE_CENTER());
                msTaskAoMapper.insert(msTaskAo);
            }
            for (MomAssSetoutMaterialDTO momAssSetoutMaterialDTO : momAssSetoutMaterialDTOS) {
                momAssSetoutMaterialDTO.setImportGroupNo(groupNo);
                //下达日计划时生成出库申请子表
                wmsInvOutBillLMapper.insertOrUpdateOutBillL(momAssSetoutMaterialDTO);
                Map<String, String> materialTypeMapping = new HashMap<>();
                materialTypeMapping.put("零件", "M");
                materialTypeMapping.put("零部件", "M");
                materialTypeMapping.put("成品", "F");
                materialTypeMapping.put("成品虚件", "S");
                materialTypeMapping.put("配套部件", "Z");
                materialTypeMapping.put("标准件", "Z");
                String itemType = materialTypeMapping.get(momAssSetoutMaterialDTO.getITEM_TYPE());
                momAssSetoutMaterialDTO.setITEM_TYPE(itemType);
                msAoMatchBillMapper.insertOrUpdateAoMatchBill(momAssSetoutMaterialDTO);
            }
            //修改bill ao 关联关系
            workService.updateMatchBill(groupNo);
            workService.updateAoTask(groupNo);
            //插入对应实体
            return null;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 新增月计划-根据最新文档变动
     * @param jsonObject
     * @return
     */

    @Transactional
    @Override
    public ResponseMsg<Object> AoMonthPlanChange(JSONObject jsonObject) throws FileNotFoundException {
        log.info("======================CEMOP系统月计划下发101库存数据=============================" + jsonObject);
        jsonObject.put("description","CEMOP系统月计划下发");
        try {
            //解压文件
            String fileUrl = jsonObject.get("fileUrl").toString();
            List<File> files = cemopXmlUtil.downloadAndExtractXMLFiles(fileUrl);
            //解析xml文件，拿到月计划内容（工作包、AO、物料）[AO不变，工作包全变，物料新增三个字段]
            FileInputStream fileInputStream = new FileInputStream(files.get(0));
            XmlReadUtil xmlReadUtil = new XmlReadUtil(fileInputStream);
            List<Map<String, String>> list1 = xmlReadUtil.getAttributesByTagName("MOM_ASS_WORKPLACE_PLAN");
            List<Map<String, String>> list2 = xmlReadUtil.getAttributesByTagName("MOM_ASS_AOTASK");
            List<Map<String, String>> list3 = xmlReadUtil.getAttributesByTagName("MOM_ASS_SETOUT_MATERIAL");
            List<MomAssWorkPackagePlanChangeDTO> momAssWorkPackagePlanChangeDTOS = new ArrayList<>();
            List<MomAssAOTaskDTO> momAssAOTaskDTOS = new ArrayList<>();
            List<MomAssSetoutMaterialDTO> momAssSetoutMaterialDTOS = new ArrayList<>();
            //工作包
            for (Map<String, String> map : list1) {
                MomAssWorkPackagePlanChangeDTO momAssWorkPackagePlanDTO = new MomAssWorkPackagePlanChangeDTO();
                xmlReadUtil.mapToDTO(map, momAssWorkPackagePlanDTO);
                momAssWorkPackagePlanChangeDTOS.add(momAssWorkPackagePlanDTO);
            }
            //AO包
            for (Map<String, String> map : list2) {
                MomAssAOTaskDTO momAssAOTaskDTO = new MomAssAOTaskDTO();
                xmlReadUtil.mapToDTO(map, momAssAOTaskDTO);
                momAssAOTaskDTOS.add(momAssAOTaskDTO);
            }
            //物料
            for (Map<String, String> map : list3) {
                MomAssSetoutMaterialDTO momAssSetoutMaterialDTO = new MomAssSetoutMaterialDTO();
                xmlReadUtil.mapToDTO(map, momAssSetoutMaterialDTO);
                momAssSetoutMaterialDTOS.add(momAssSetoutMaterialDTO);
            }
            String groupNo = ComUtil.getId();
            //循环插入工作包
            for (MomAssWorkPackagePlanChangeDTO momAssWorkPackagePlanChangeDTO : momAssWorkPackagePlanChangeDTOS) {
                MsTaskPackageChange msTaskPackage = new MsTaskPackageChange();
                msTaskPackage.setMsTaskPackageId(momAssWorkPackagePlanChangeDTO.getWKSTTN_PLN_TAB_PK());
                msTaskPackage.setProductCode(momAssWorkPackagePlanChangeDTO.getMODLS_ECD());
                msTaskPackage.setBatchNo(momAssWorkPackagePlanChangeDTO.getBCH_NO());
                msTaskPackage.setStartPlaneNo(momAssWorkPackagePlanChangeDTO.getSORTIE_NO());
                msTaskPackage.setDepartCode(momAssWorkPackagePlanChangeDTO.getMANUFA_BCPLT_ECD());
                msTaskPackage.setPrfsnlEcd(momAssWorkPackagePlanChangeDTO.getPRFSNL_ECD());
                msTaskPackage.setWksttnEcd(momAssWorkPackagePlanChangeDTO.getWKSTTN_ECD());
                msTaskPackage.setWksttnName(momAssWorkPackagePlanChangeDTO.getWKSTTN_NAME());
                msTaskPackage.setPlanStartDate(momAssWorkPackagePlanChangeDTO.getPLN_STRTWK_TM());
                msTaskPackage.setPlanEndDate(momAssWorkPackagePlanChangeDTO.getPLNCOP_TM());
                msTaskPackage.setPctlStrtwkTm(momAssWorkPackagePlanChangeDTO.getPCTL_STRTWK_TM());
                msTaskPackage.setPctlCpltdTm(momAssWorkPackagePlanChangeDTO.getPCTL_CPLTD_TM());
                msTaskPackage.setPrntWksttnEcd(momAssWorkPackagePlanChangeDTO.getPRNT_WKSTTN_ECD());
                msTaskPackage.setMilstnEcd(momAssWorkPackagePlanChangeDTO.getMILSTN_ECD());
                msTaskPackage.setMilstnName(momAssWorkPackagePlanChangeDTO.getMILSTN_NAME());
                msTaskPackage.setNewMissionNo(momAssWorkPackagePlanChangeDTO.getNEW_MISSION_NO());
                msTaskPackage.setNewMissionName(momAssWorkPackagePlanChangeDTO.getNEW_MISSION_NAME());
                msTaskPackage.setPlnStusCd(momAssWorkPackagePlanChangeDTO.getPLN_STUS_CD());
                msTaskPackage.setAsmblCycNv(momAssWorkPackagePlanChangeDTO.getASMBL_CYC_NV());
                msTaskPackage.setAsmblMilstnPlnPk(momAssWorkPackagePlanChangeDTO.getASMBL_MILSTN_PLN_PK());
                msTaskPackage.setProdMthplPk(momAssWorkPackagePlanChangeDTO.getPROD_MTHPL_PK());
                msTaskPackage.setWoNo(momAssWorkPackagePlanChangeDTO.getWO_NO());
                msTaskPackage.setWoType(momAssWorkPackagePlanChangeDTO.getWO_TYPE());
                msTaskPackage.setPublishDate(momAssWorkPackagePlanChangeDTO.getPUBLISH_DATE());
                msTaskPackage.setCreatedBy(momAssWorkPackagePlanChangeDTO.getPUBLISH_EMP());
                msTaskPackage.setIsAbleTurnOver(momAssWorkPackagePlanChangeDTO.getIS_ABLE_TURN_OVER());
                msTaskPackage.setTurnOverStatus(momAssWorkPackagePlanChangeDTO.getTURN_OVER_STATUS());
                msTaskPackage.setTurnOverSb(momAssWorkPackagePlanChangeDTO.getTURN_OVER_SB());
                msTaskPackage.setTurnOverDate(momAssWorkPackagePlanChangeDTO.getTURN_OVER_DATE());
                msTaskPackage.setReceiveUnit(momAssWorkPackagePlanChangeDTO.getRECEIVE_UNIT());
                msTaskPackage.setReceiveEmp(momAssWorkPackagePlanChangeDTO.getRECEIVE_EMP());
                msTaskPackage.setReceiveDate(momAssWorkPackagePlanChangeDTO.getRECEIVE_DATE());
                msTaskPackage.setLogisticsArea(momAssWorkPackagePlanChangeDTO.getLOGISTICS_AREA());
                msTaskPackage.setManufaSectnEcd(momAssWorkPackagePlanChangeDTO.getMANUFA_SECTN_ECD());
                msTaskPackage.setBelongMonth(momAssWorkPackagePlanChangeDTO.getBELONG_MONTH());
                msTaskPackage.setPlanBy(momAssWorkPackagePlanChangeDTO.getPLAN_BY());
                msTaskPackage.setPlanDate(momAssWorkPackagePlanChangeDTO.getPLAN_DATE());
                msTaskPackage.setWeekTime(momAssWorkPackagePlanChangeDTO.getBELONG_WEEK());
                msTaskPackage.setWksttnId(momAssWorkPackagePlanChangeDTO.getWKSTTN_ID());
                msTaskPackage.setMilstnId(momAssWorkPackagePlanChangeDTO.getMILSTN_ID());
                msTaskPackage.setEarlyPlanStartDate(momAssWorkPackagePlanChangeDTO.getEARLY_PLAN_START_DATE());
                msTaskPackage.setEarlyPlanEndDate(momAssWorkPackagePlanChangeDTO.getEARLY_PLAN_END_DATE());
                msTaskPackage.setQuarterStartDate(momAssWorkPackagePlanChangeDTO.getQUARTER_START_DATE());
                msTaskPackage.setQuarterEndDate(momAssWorkPackagePlanChangeDTO.getQUARTER_END_DATE());
                msTaskPackage.setMonthlyStartDate(momAssWorkPackagePlanChangeDTO.getMONTHLY_START_DATE());
                msTaskPackage.setMonthlyEndDate(momAssWorkPackagePlanChangeDTO.getMONTHLY_END_DATE());
                msTaskPackage.setWoId(momAssWorkPackagePlanChangeDTO.getWO_ID());
                msTaskPackage.setUseSectnEcd(momAssWorkPackagePlanChangeDTO.getUSE_SECTN_ECD());
                msTaskPackage.setUseBcpltEcd(momAssWorkPackagePlanChangeDTO.getUSE_BCPLT_ECD());
                msTaskPackage.setMissionNo(momAssWorkPackagePlanChangeDTO.getMISSION_NO());
                msTaskPackage.setAppraisePlanStartDate(momAssWorkPackagePlanChangeDTO.getAPPRAISE_PLAN_START_DATE());
                msTaskPackage.setAppraisePlanEndDate(momAssWorkPackagePlanChangeDTO.getAPPRAISE_PLAN_END_DATE());
                msTaskPackage.setOutsourceStatus(momAssWorkPackagePlanChangeDTO.getOUTSOURCE_STATUS());
                msTaskPackage.setPackageCode((momAssWorkPackagePlanChangeDTO.getWKSTTN_ECD())); //工作包编码
                msTaskPackage.setPackageName(momAssWorkPackagePlanChangeDTO.getWKSTTN_NAME()); //工作包名称
                msTaskPackage.setWorkpackageCode(momAssWorkPackagePlanChangeDTO.getWKSTTN_ECD()); //工作包属性
                msTaskPackage.setState("00");
                msTaskPackage.setAState("00");
                msTaskPackage.setSortingStatus("00");
                msTaskPackage.setDeliveryState("00");
                msTaskPackage.setImportGroupNo(groupNo);
                msTaskPackageChangeMapper.insert(msTaskPackage);
            }
            //新增AO分拣任务
            for (MomAssAOTaskDTO momAssAOTask : momAssAOTaskDTOS) {
                WmsInvOutBillH wmsInvOutBillH = new WmsInvOutBillH();
                wmsInvOutBillH.setWmsInvOutBillHId(momAssAOTask.getMOM_ASS_AOTASK_ID());
                wmsInvOutBillH.setProductCode(momAssAOTask.getMODLS_ECD());
                wmsInvOutBillH.setBatchNo(momAssAOTask.getBCH_NO());
                wmsInvOutBillH.setStartLotNo(momAssAOTask.getSORTIE_NO());
                wmsInvOutBillH.setAoNo(momAssAOTask.getAO_NO());
                wmsInvOutBillHMapper.insert(wmsInvOutBillH);
                //修改工作包站位
                UpdateWrapper<MsTaskPackage> updateWrapper = new UpdateWrapper<>();
                updateWrapper.set("made_center",momAssAOTask.getSYS_MADE_CENTER());
                updateWrapper.eq("import_group_no",groupNo);
    //                updateWrapper.eq("package_code",momAssAOTask.getWORKPACKAGE_CODE());
                if (momAssAOTask.getSYS_MADE_CENTER()!=null && momAssAOTask.getSYS_MADE_CENTER().length() > 0)
                {
                    iMsTaskPackageService.update(updateWrapper);
                }
                List<MomAssWorkPackagePlanChangeDTO> collect = momAssWorkPackagePlanChangeDTOS.stream().filter(momAssWorkPackagePlanChangeDTO -> momAssWorkPackagePlanChangeDTO.getWKSTTN_ECD().equals(momAssAOTask.getWKSTTN_ECD())).collect(Collectors.toList());
                String momAssWorkpackagePlanId2 = collect.get(0).getWKSTTN_PLN_TAB_PK();
                //插入AO信息
                MsTaskAo msTaskAo = new MsTaskAo();
                msTaskAo.setMsTaskAoId(momAssAOTask.getMOM_ASS_AOTASK_ID());
                msTaskAo.setProductCode(momAssAOTask.getMODLS_ECD());
                msTaskAo.setBatchNo(momAssAOTask.getBCH_NO());
                msTaskAo.setPlanId(momAssAOTask.getPLAN_ID());
                msTaskAo.setStartPlaneNo(momAssAOTask.getSORTIE_NO());
                msTaskAo.setDepartCode(momAssAOTask.getMANUFA_BCPLT_ECD());
                msTaskAo.setPackageCode(momAssAOTask.getWKSTTN_ECD());
                msTaskAo.setAoCode(momAssAOTask.getAO_NO());
                msTaskAo.setAoName(momAssAOTask.getAO_NAME());
                msTaskAo.setRequiredTime(momAssAOTask.getPLAN_START_DATE());
                msTaskAo.setState("00");
                msTaskAo.setAState("00");
                msTaskAo.setCreatedBy(momAssAOTask.getCREATED_BY());
                // 使用 SimpleDateFormat 格式化日期
                Date now = new Date();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
                String formattedDate = sdf.format(now);
                msTaskAo.setCreationDate(momAssAOTask.getCREATION_DATE());
                msTaskAo.setLastUpdatedBy(momAssAOTask.getLAST_UPDATED_BY());
                msTaskAo.setLastUpdateDate(momAssAOTask.getLAST_UPDATE_DATE());
                msTaskAo.setMsTaskPackageId(momAssWorkpackagePlanId2);
                if (momAssAOTask.getLAST_UPDATE_IP().isEmpty())
                {
                    msTaskAo.setLastUpdateIp(momAssAOTask.getLAST_UPDATE_IP());
                }
                msTaskAo.setImportGroupNo(groupNo);
                msTaskAo.setSortingStatus("00");
                msTaskAo.setStation(momAssAOTask.getSYS_MADE_CENTER());
                msTaskAoMapper.insert(msTaskAo);
            }
            //插入物料信息
            for (MomAssSetoutMaterialDTO momAssSetoutMaterialDTO : momAssSetoutMaterialDTOS) {
                momAssSetoutMaterialDTO.setImportGroupNo(groupNo);
                //下达日计划时生成出库申请子表
                wmsInvOutBillLMapper.insertOrUpdateOutBillL(momAssSetoutMaterialDTO);
                Map<String, String> materialTypeMapping = new HashMap<>();
                materialTypeMapping.put("零件", "M");
                materialTypeMapping.put("配套零件", "M");
                materialTypeMapping.put("零部件", "M");
                materialTypeMapping.put("成品", "F");
                materialTypeMapping.put("配套成品", "F");
                materialTypeMapping.put("成品虚件", "S");
                materialTypeMapping.put("配套部件", "Z");
                materialTypeMapping.put("标准件", "Z");
                Map<String, String> updateFlagMapping = new HashMap<>();
                updateFlagMapping.put("0", "U");
                updateFlagMapping.put("1", "A");
                updateFlagMapping.put("2", "D");
                updateFlagMapping.put("3", "3");
                String itemType = materialTypeMapping.get(momAssSetoutMaterialDTO.getITEM_TYPE());
                String updateFlag = materialTypeMapping.get(momAssSetoutMaterialDTO.getUPDATE_FLAG());
                momAssSetoutMaterialDTO.setITEM_TYPE(itemType);
                momAssSetoutMaterialDTO.setUPDATE_FLAG(updateFlag);
                msAoMatchBillMapper.insertOrUpdateAoMatchBill(momAssSetoutMaterialDTO);
            }
            //修改bill ao 关联关系
            workService.updateMatchBill(groupNo);
            // workService.updateAoTask(groupNo);
            jsonObject.put("msg","Cemop下发月计划成功");
            jsonObject.put("status","2");
            cemopServiceImpl.sendSortBackResult(jsonObject);
            return null;
        } catch (FileNotFoundException e) {
            jsonObject.put("msg","失败："+e);
            jsonObject.put("status","3");
            cemopServiceImpl.sendSortBackResult(jsonObject);
            throw new RuntimeException(e);
        }
    }



    @Transactional
    @Override
    public ResponseMsg<Object> AoWeekPlan(@RequestBody JSONObject jsonObject) {
        System.out.println("=========================Cemop周计划下发==========================="+jsonObject);
        try {
            HashMap res = new HashMap();
            String fileUrl=jsonObject.get("fileUrl").toString();
            System.out.println("=========================下载zip文件并获取File文件===========================");
            //解压文件
            List<File> files = cemopXmlUtil.downloadAndExtractXMLFiles(fileUrl);
            //解析xml文件，拿到月计划内容（工作包、AO、物料）
            FileInputStream fileInputStream = new FileInputStream(files.get(0));
            XmlReadUtil xmlReadUtil = new XmlReadUtil(fileInputStream);
            //获取工作包
            List<Map<String, String>> list1 = xmlReadUtil.getAttributesByTagName("MOM_ASS_WORKPACKAGE_PLAN");
            List<MomAssWorkPackagePlanDTO> momAssWorkPackagePlanDTOs = new ArrayList<>();
            for (Map<String, String> map : list1) {
                MomAssWorkPackagePlanDTO momAssWorkPackagePlanDTO = new MomAssWorkPackagePlanDTO();
                xmlReadUtil.mapToDTO(map,momAssWorkPackagePlanDTO);
                momAssWorkPackagePlanDTOs.add(momAssWorkPackagePlanDTO);
            }
            for (MomAssWorkPackagePlanDTO momAssWorkPackagePlanDTO : momAssWorkPackagePlanDTOs) {
                UpdateWrapper<MsTaskAo> updAOWeek = new UpdateWrapper<>();
                updAOWeek.set("required_time",momAssWorkPackagePlanDTO.getPLAN_START_DATE());
                updAOWeek.eq("MS_TASK_PACKAGE_ID",momAssWorkPackagePlanDTO.getMOM_ASS_WORKPACKAGE_PLAN_ID());
                iMsTaskAoService.update(updAOWeek);
                UpdateWrapper<MsTaskPackage> updPackageWeek = new UpdateWrapper<>();
                updPackageWeek.set("plan_start_date",momAssWorkPackagePlanDTO.getPLAN_START_DATE())
                        .set("plan_end_date",momAssWorkPackagePlanDTO.getPLAN_END_DATE())
                        .set("required_time",momAssWorkPackagePlanDTO.getPLAN_START_DATE())
                        .set("week_time",momAssWorkPackagePlanDTO.getBELONG_WEEK());
                updPackageWeek.eq("MS_TASK_PACKAGE_ID",momAssWorkPackagePlanDTO.getMOM_ASS_WORKPACKAGE_PLAN_ID());
                iMsTaskPackageService.update(updPackageWeek);
            }
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        return null;
    }

    @Override
    public ResponseMsg<Object> AoWeekPlanChange(JSONObject jsonObject) throws FileNotFoundException {
        log.info("=================================CEMOP系统周计划通知101库存数据====================================" + jsonObject);
        jsonObject.put("description","CEMOP系统周计划下发");
        try {
            HashMap res = new HashMap();
            String fileUrl=jsonObject.get("fileUrl").toString();
            log.info("============================下载zip文件并获取File文件==============================================");
            //解压文件
            List<File> files = cemopXmlUtil.downloadAndExtractXMLFiles(fileUrl);
            //解析xml文件，拿到月计划内容（工位内容）
            FileInputStream fileInputStream = new FileInputStream(files.get(0));
            XmlReadUtil xmlReadUtil = new XmlReadUtil(fileInputStream);
            //获取工位信息
            List<Map<String, String>> list1 = xmlReadUtil.getAttributesByTagName("MOM_ASS_WORKPLACE_PLAN");
            List<MomAssWorkPackagePlanChangeDTO> momAssWorkPackagePlanChangeDTOs = new ArrayList<>();
            for (Map<String, String> map : list1) {
                MomAssWorkPackagePlanChangeDTO momAssWorkPackagePlanChangeDTO = new MomAssWorkPackagePlanChangeDTO();
                xmlReadUtil.mapToDTO(map,momAssWorkPackagePlanChangeDTO);
                momAssWorkPackagePlanChangeDTOs.add(momAssWorkPackagePlanChangeDTO);
            }
            for (MomAssWorkPackagePlanChangeDTO momAssWorkPackagePlanChangeDTO : momAssWorkPackagePlanChangeDTOs) {
                UpdateWrapper<MsTaskAo> updAOWeek = new UpdateWrapper<>();
                //计划开工时间
                updAOWeek.set("required_time",momAssWorkPackagePlanChangeDTO.getPLN_STRTWK_TM());
                //工位计划表主键
                updAOWeek.eq("MS_TASK_PACKAGE_ID",momAssWorkPackagePlanChangeDTO.getWKSTTN_PLN_TAB_PK());
                iMsTaskAoService.update(updAOWeek);
                UpdateWrapper<MsTaskPackage> updPackageWeek = new UpdateWrapper<>();
                updPackageWeek.set("plan_start_date",momAssWorkPackagePlanChangeDTO.getPLN_STRTWK_TM())
                        .set("plan_end_date",momAssWorkPackagePlanChangeDTO.getPLNCOP_TM())
                        .set("required_time",momAssWorkPackagePlanChangeDTO.getPLN_STRTWK_TM())
                        .set("week_time",momAssWorkPackagePlanChangeDTO.getBELONG_WEEK());
                updPackageWeek.eq("MS_TASK_PACKAGE_ID",momAssWorkPackagePlanChangeDTO.getWKSTTN_PLN_TAB_PK());
                iMsTaskPackageService.update(updPackageWeek);
            }
            jsonObject.put("msg","Cemop下发周计划成功");
            jsonObject.put("status","2");
            cemopServiceImpl.sendSortBackResult(jsonObject);
            return null;
        } catch (FileNotFoundException e) {
            jsonObject.put("msg","失败："+e);
            jsonObject.put("status","3");
            cemopServiceImpl.sendSortBackResult(jsonObject);
            throw new RuntimeException(e);
        }
    }

    @Transactional
    @Override
    public ResponseMsg<Object> AoDayPlan(@RequestBody JSONObject jsonObject) {
        System.out.println("=========================Cemop日计划下发==========================="+jsonObject);
        try {
            HashMap res = new HashMap();
            String fileUrl=jsonObject.get("fileUrl").toString();
            System.out.println("=========================下载zip文件并获取File文件===========================");
            //解压文件
            List<File> files = cemopXmlUtil.downloadAndExtractXMLFiles(fileUrl);
            //解析xml文件，拿到日计划内容（工作包）
            FileInputStream fileInputStream = new FileInputStream(files.get(0));
            XmlReadUtil xmlReadUtil = new XmlReadUtil(fileInputStream);
            //获取工作包
            List<Map<String, String>> list1  = xmlReadUtil.getAttributesByTagName("MOM_ASS_WORKPACKAGE_PLAN");
            List<MomAssWorkPackagePlanDTO> momAssWorkPackagePlanDTOs = new ArrayList<>();
            for (Map<String, String> map : list1) {
                MomAssWorkPackagePlanDTO momAssWorkPackagePlanDTO = new MomAssWorkPackagePlanDTO();
                xmlReadUtil.mapToDTO(map,momAssWorkPackagePlanDTO);
                momAssWorkPackagePlanDTOs.add(momAssWorkPackagePlanDTO);
            }
            for (MomAssWorkPackagePlanDTO momAssWorkPackagePlanDTO : momAssWorkPackagePlanDTOs) {
                UpdateWrapper<MsTaskPackage> updPackageDay = new UpdateWrapper<>();
                updPackageDay.set("REQUIRED_TIME",momAssWorkPackagePlanDTO.getPLAN_START_DATE())
                        .set("DELIVERY_TIME",momAssWorkPackagePlanDTO.getPLAN_START_DATE())
                        .set("DAILY_TIME",momAssWorkPackagePlanDTO.getBELONG_DAY());
                updPackageDay.eq("START_PLANE_NO",momAssWorkPackagePlanDTO.getSORTIE_NO())
                        .eq("BATCH_NO",momAssWorkPackagePlanDTO.getBCH_NO())
                        .eq("PRODUCT_CODE",momAssWorkPackagePlanDTO.getMODLS_ECD())
                        .eq("PACKAGE_CODE",momAssWorkPackagePlanDTO.getWORKPACKAGE_CODE());
                iMsTaskPackageService.update(updPackageDay);
                UpdateWrapper<MsTaskAo> updAODay = new UpdateWrapper<>();
                updAODay.set("REQUIRED_TIME",momAssWorkPackagePlanDTO.getPLAN_START_DATE())
//                        .set("DOC_NUMBER",momAssWorkPackagePlanDTO.getPLAN_START_DATE())
//                        .set("MATERIAL_GIST",momAssWorkPackagePlanDTO.getPLAN_START_DATE())
                        .set("DAILY_TIME",momAssWorkPackagePlanDTO.getBELONG_DAY());
                updAODay.eq("START_PLANE_NO",momAssWorkPackagePlanDTO.getSORTIE_NO())
                        .eq("BATCH_NO",momAssWorkPackagePlanDTO.getBCH_NO())
                        .eq("PRODUCT_CODE",momAssWorkPackagePlanDTO.getMODLS_ECD())
                        .eq("PACKAGE_CODE",momAssWorkPackagePlanDTO.getWORKPACKAGE_CODE());
                iMsTaskAoService.update(updAODay);
            }
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        return null;
    }

    @Transactional
    @Override
    public ResponseMsg<Object> AoDayPlanChange(JSONObject jsonObject) throws FileNotFoundException {
        log.info("==========================Cemop日计划下发=============================="+jsonObject);
        jsonObject.put("description","CEMOP系统日计划下发");
        try {
            HashMap res = new HashMap();
            String fileUrl=jsonObject.get("fileUrl").toString();
            System.out.println("=========================下载zip文件并获取File文件===========================");
            //解压文件
            List<File> files = cemopXmlUtil.downloadAndExtractXMLFiles(fileUrl);
            //解析xml文件，拿到日计划内容（工作包）
            FileInputStream fileInputStream = new FileInputStream(files.get(0));
            XmlReadUtil xmlReadUtil = new XmlReadUtil(fileInputStream);
            //获取工位信息
            List<Map<String, String>> list1  = xmlReadUtil.getAttributesByTagName("MOM_ASS_WORKPLACE_PLAN");
            List<MomAssWorkPackagePlanChangeDTO> momAssWorkPackagePlanChangeDTOs = new ArrayList<>();
            for (Map<String, String> map : list1) {
                MomAssWorkPackagePlanChangeDTO momAssWorkPackagePlanChangeDTO = new MomAssWorkPackagePlanChangeDTO();
                xmlReadUtil.mapToDTO(map,momAssWorkPackagePlanChangeDTO);
                momAssWorkPackagePlanChangeDTOs.add(momAssWorkPackagePlanChangeDTO);
            }
            for (MomAssWorkPackagePlanChangeDTO momAssWorkPackagePlanChangeDTO : momAssWorkPackagePlanChangeDTOs) {
                UpdateWrapper<MsTaskPackage> updPackageDay = new UpdateWrapper<>();
                updPackageDay.set("REQUIRED_TIME",momAssWorkPackagePlanChangeDTO.getPLN_STRTWK_TM())
                        .set("DELIVERY_TIME",momAssWorkPackagePlanChangeDTO.getPLN_STRTWK_TM()); //所属日取计划开工时间
                updPackageDay.eq("START_PLANE_NO",momAssWorkPackagePlanChangeDTO.getSORTIE_NO())
                        .eq("BATCH_NO",momAssWorkPackagePlanChangeDTO.getBCH_NO())
                        .eq("PRODUCT_CODE",momAssWorkPackagePlanChangeDTO.getMODLS_ECD())
                        .eq("PACKAGE_CODE",momAssWorkPackagePlanChangeDTO.getWKSTTN_ECD());
                iMsTaskPackageService.update(updPackageDay);
                UpdateWrapper<MsTaskAo> updAODay = new UpdateWrapper<>();
                updAODay.set("REQUIRED_TIME",momAssWorkPackagePlanChangeDTO.getPLN_STRTWK_TM())
                        .set("DAILY_TIME",momAssWorkPackagePlanChangeDTO.getPLN_STRTWK_TM()); //日计划要求时间取开工时间
                updAODay.eq("START_PLANE_NO",momAssWorkPackagePlanChangeDTO.getSORTIE_NO())
                        .eq("BATCH_NO",momAssWorkPackagePlanChangeDTO.getBCH_NO())
                        .eq("PRODUCT_CODE",momAssWorkPackagePlanChangeDTO.getMODLS_ECD())
                        .eq("PACKAGE_CODE",momAssWorkPackagePlanChangeDTO.getWKSTTN_ECD());
                iMsTaskAoService.update(updAODay);
            }
            jsonObject.put("msg","Cemop下发日计划成功");
            jsonObject.put("status","2");
            cemopServiceImpl.sendSortBackResult(jsonObject);
            return null;
        } catch (FileNotFoundException e) {
            jsonObject.put("msg","失败："+e);
            jsonObject.put("status","3");
            cemopServiceImpl.sendSortBackResult(jsonObject);
            throw new RuntimeException(e);
        }
    }

    /**
     * 装配系统日计划下发AO至101库存-20250224新增
     * @param jsonObject
     * @return
     * @throws FileNotFoundException
     */
    @Override
    @Transactional
    public ResponseMsg<Object> AoDayPlantoChange(JSONObject jsonObject) throws FileNotFoundException {
        log.info("==========================Cemop日计划AO下发=============================="+jsonObject);
        HashMap res = new HashMap();
        String fileUrl=jsonObject.get("fileUrl").toString();
        System.out.println("=========================下载zip文件并获取File文件===========================");
        //解压文件
        List<File> files = cemopXmlUtil.downloadAndExtractXMLFiles(fileUrl);
        //解析xml文件，拿到日计划内容（工作包）
        FileInputStream fileInputStream = new FileInputStream(files.get(0));
        XmlReadUtil xmlReadUtil = new XmlReadUtil(fileInputStream);
        //获取工位信息
        List<Map<String, String>> list1  = xmlReadUtil.getAttributesByTagName("MOM_ASS_AOTASK");
        List<MomAssAOTaskDTO> momAssAOTaskDTOS = new ArrayList<>();
        //AO包
        for (Map<String, String> map : list1) {
            MomAssAOTaskDTO momAssAOTaskDTO = new MomAssAOTaskDTO();
            xmlReadUtil.mapToDTO(map, momAssAOTaskDTO);
            momAssAOTaskDTOS.add(momAssAOTaskDTO);
        }
        //根据主键ID查询并更新工作包
        for (MomAssAOTaskDTO momAssAOTaskDTO : momAssAOTaskDTOS) {
            LambdaQueryWrapper<MsTaskAo> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(MsTaskAo::getMsTaskAoId, momAssAOTaskDTO.getMOM_ASS_AOTASK_ID());
            MsTaskAo msTaskAo = msTaskAoMapper.selectOne(queryWrapper);
            //查询工作包
            LambdaQueryWrapper<MsTaskPackage> queryWrapper2 = new LambdaQueryWrapper<>();
            queryWrapper2.eq(MsTaskPackage::getMsTaskPackageId, msTaskAo.getMsTaskPackageId());
            MsTaskPackage msTaskPackage = msTaskPackageMapper.selectOne(queryWrapper2);
            msTaskPackage.setRequiredTime(momAssAOTaskDTO.getPLAN_START_DATE());
            msTaskPackage.setDeliveryTime(momAssAOTaskDTO.getPLAN_START_DATE());
            LambdaQueryWrapper<MsTaskPackage> queryWrapper1 = new LambdaQueryWrapper<>();
            queryWrapper1.eq(MsTaskPackage::getMsTaskPackageId, msTaskAo.getMsTaskPackageId());
            iMsTaskPackageService.update(msTaskPackage,queryWrapper1);
            UpdateWrapper<MsTaskAo> updAODay = new UpdateWrapper<>();
            updAODay.set("REQUIRED_TIME",momAssAOTaskDTO.getPLAN_START_DATE())
                    .set("DAILY_TIME",momAssAOTaskDTO.getPLAN_START_DATE()); //日计划要求时间取开工时间
            updAODay.eq("START_PLANE_NO",momAssAOTaskDTO.getSORTIE_NO())
                    .eq("BATCH_NO",momAssAOTaskDTO.getBCH_NO())
                    .eq("PRODUCT_CODE",momAssAOTaskDTO.getMODLS_ECD())
                    .eq("PACKAGE_CODE",momAssAOTaskDTO.getWKSTTN_ECD());
            iMsTaskAoService.update(updAODay);
        }
        return null;
    }

    @Override
    public ResponseMsg<Object> AoMatchPlanExecute() {
        ResponseMsg<Object> responseMsg = new ResponseMsg<>();
        long startTime = System.currentTimeMillis();
        String taskId = ComUtil.getId();
        msConsoleDao.addTask(taskId, "ALL");
        ResponseMsg<Object> result = AoMatchPlan();
        pointPackageSortService.assginPallet();
        if (result.getMessage().equals("执行成功")) {
            responseMsg.setRetCode("200").setMessage("执行分配分拣任务成功！");
            msDeliveryPackageInfoRest.upDeliveryStatus();
            cemopService.sendMatchBillInfo();
        } else {
            responseMsg.setMessage("执行分配分拣任务失败！").setRetCode("201");
        }
        long endTime = System.currentTimeMillis();
        HashMap ret = new HashMap();
        ret.put("taskId", taskId);
        ret.put("retCode", responseMsg.getRetCode());
        ret.put("retMsg", responseMsg.getMessage());
        ret.put("costTime", ((endTime - startTime) / 1000) + "s");
        msConsoleDao.updateTask(ret);
        return responseMsg;
    }

    /**
     * 虚拟预配套数据准备
     *
     * @return
     */
    @Transactional
    public List<MsTaskPackage> AoMatchPlanDataPreparation() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        try{
            //删除未分拣材料,并排查已配套齐全的
            LambdaQueryWrapper<MsAoMatchInfo> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(MsAoMatchInfo::getIsSort, 'N');
            imsAoMatchInfoService.remove(queryWrapper);
            //删除库存临时占用表
            imsSortItemInventoryTempService.remove(null);
            //质保期过期的不在使用配套
            wmsItemInventoryMapper.UpdateinvStatus();
            UpdateWrapper<MsTaskPackage> updateWrapper = new UpdateWrapper<>();
            updateWrapper.set("remark", "");
            iMsTaskPackageService.update(updateWrapper);
            //更新没有物料的情况的Ao状态08
            msTaskAoMapper.updateState();
            LambdaQueryWrapper<MsTaskPackage> queryWrapper1 = new LambdaQueryWrapper<>();
            queryWrapper1.ne(MsTaskPackage::getDeliveryState, "04");
            queryWrapper1.orderByAsc(MsTaskPackage::getStartPlaneNo);
            List<MsTaskPackage> list = iMsTaskPackageService.list(queryWrapper1);
            for (MsTaskPackage msTaskPackage : list) {
                String msTaskPackageId = msTaskPackage.getMsTaskPackageId();
                String batchNo = msTaskPackage.getBatchNo();
                String startPlaneNo = msTaskPackage.getStartPlaneNo();
                LambdaQueryWrapper<MsTaskAo> queryWrapper2 = new LambdaQueryWrapper<>();
                queryWrapper2.eq(MsTaskAo::getMsTaskPackageId, msTaskPackageId);
                queryWrapper2.eq(MsTaskAo::getBatchNo, batchNo);
                queryWrapper2.eq(MsTaskAo::getStartPlaneNo, startPlaneNo);
                queryWrapper2.ne(MsTaskAo::getState, "08");
                queryWrapper2.orderByAsc(MsTaskAo::getDailyTime);
                List<MsTaskAo> list1 = iMsTaskAoService.list(queryWrapper2);
                msTaskPackage.setMsTaskAoList(list1);
                for (MsTaskAo msTaskAo : list1) {
                    List<MsAoMatchBill> msAoMatchBills = msAoMatchBillMapper.queryAoMatchBill(msTaskAo.getMsTaskAoId());
                    msTaskAo.setMsAoMatchBillList(msAoMatchBills);
                }
            }
            //记录日志
            LocalLogDTO dto = new LocalLogDTO();
            dto.setLevel("INFO");
            dto.setMessage("删除未分拣材料,并排查已配套齐全的、删除库存临时占用表、质保期过期的不在使用配套、更新没有物料的情况的Ao状态08");
            dto.setRequestParam("");
            dto.setResponseParam(JSONObject.toJSONString(list));
            dto.setMethod("AoMatchPlan");
            dto.setLoggerName("虚拟预配套数据准备");
            dto.setIpAddress(request.getRemoteAddr());
            cemopService.saveLocalLog(dto);
            return list;
        }
        catch (Exception e){
            //记录日志
            LocalLogDTO dto = new LocalLogDTO();
            dto.setLevel("Error");
            dto.setMessage("删除未分拣材料,并排查已配套齐全的、删除库存临时占用表、质保期过期的不在使用配套、更新没有物料的情况的Ao状态08");
            dto.setRequestParam("");
            dto.setResponseParam(e.getMessage());
            dto.setMethod("AoMatchPlan");
            dto.setLoggerName("虚拟预配套数据准备");
            dto.setIpAddress(request.getRemoteAddr());
            cemopService.saveLocalLog(dto);
            return new ArrayList<>();
        }
    }

    @Transactional
    @Override
    public ResponseMsg<Object> AoMatchPlan() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        try {
            List<MsTaskPackage> msTaskPackages = AoMatchPlanDataPreparation();
            for (MsTaskPackage msTaskPackage : msTaskPackages) {
                for (MsTaskAo msTaskAo : msTaskPackage.getMsTaskAoList()) {
                    for (MsAoMatchBill msAoMatchBill : msTaskAo.getMsAoMatchBillList()) {
                        if (msAoMatchBill.getItemQty().compareTo(BigDecimal.ZERO) < 0) {
                            continue;
                        }
                        //125-160 工艺更改
                        artChange(msTaskPackage, msTaskAo, msAoMatchBill);
                        //161-521 台账占用，库存预分配，占用缓存箱
                        itemInventoryOccupy(msTaskPackage, msTaskAo, msAoMatchBill);
                    }
                    //标准件配套
                    standardAssort(msTaskPackage, msTaskAo);
                    //793-912 配套验证
                    AssortVerify(msTaskPackage, msTaskAo);
                }
            }
            //记录日志
            LocalLogDTO dto = new LocalLogDTO();
            dto.setRequestParam("");
            dto.setLevel("INFO");
            dto.setMessage("虚拟计算配套任务[工艺更改、(台账占用，库存预分配，占用缓存箱)、标准件配套、配套验证方法]");
            dto.setResponseParam("");
            dto.setMethod("AoMatchPlan");
            dto.setLoggerName("虚拟计算配套任务");
            dto.setIpAddress(request.getRemoteAddr());
            cemopService.saveLocalLog(dto);
            return new ResponseMsg<>().setMessage("执行成功").setRetCode("200");
        } catch (Exception e) {
            e.printStackTrace();
            //记录日志
            LocalLogDTO dto = new LocalLogDTO();
            dto.setRequestParam("");
            dto.setLevel("Error");
            dto.setMessage("虚拟计算配套任务[工艺更改、(台账占用，库存预分配，占用缓存箱)、标准件配套、配套验证方法]");
            dto.setResponseParam(e.getMessage());
            dto.setMethod("AoMatchPlan");
            dto.setLoggerName("虚拟计算配套任务");
            dto.setIpAddress(request.getRemoteAddr());
            cemopService.saveLocalLog(dto);
            return new ResponseMsg<>().setMessage("执行失败").setRetCode("500");
        }
    }

    @Transactional
    public void AssortVerify(MsTaskPackage msTaskPackage, MsTaskAo msTaskAo) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        try {
            //计算是否全部配套完成
            //1.AO物料配套清单数量求和 以物料编码和AO分拣任务分组
            //2.AO物料配套信息中未配套和已配套的配套数量求和
            //3.通过物料编码相等且 清单中的配套数量大于信息的数量才计数
            int countQty = msTaskAoMapper.countQty(msTaskAo.getMsTaskAoId());
            LambdaUpdateWrapper<MsTaskAo> updateWrapper = new LambdaUpdateWrapper<>();
            //判断数量大于0则配套完成反之则缺件
            if (countQty > 0) {
                updateWrapper.set(MsTaskAo::getState, "04");
            } else {
                updateWrapper.set(MsTaskAo::getState, "02");
            }
            updateWrapper.eq(MsTaskAo::getMsTaskAoId, msTaskAo.getMsTaskAoId());
            iMsTaskAoService.update(updateWrapper);
            LambdaQueryWrapper<MsTaskAo> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(MsTaskAo::getPackageCode, msTaskPackage.getPackageCode());
            queryWrapper.eq(MsTaskAo::getBatchNo, msTaskPackage.getBatchNo());
            queryWrapper.eq(MsTaskAo::getStartPlaneNo, msTaskPackage.getStartPlaneNo());
            queryWrapper.eq(MsTaskAo::getState, "04");
            long count = iMsTaskAoService.count(queryWrapper);
            if (count > 0) {
                LambdaUpdateWrapper<MsTaskPackage> updateWrapper1 = new LambdaUpdateWrapper<>();
                updateWrapper1.set(MsTaskPackage::getState, "04");
                updateWrapper1.set(MsTaskPackage::getAState, "B");
                updateWrapper1.eq(MsTaskPackage::getMsTaskPackageId, msTaskPackage.getMsTaskPackageId());
                iMsTaskPackageService.update(updateWrapper1);
            } else {
                LambdaUpdateWrapper<MsTaskPackage> updateWrapper1 = new LambdaUpdateWrapper<>();
                updateWrapper1.set(MsTaskPackage::getState, "02");
                updateWrapper1.set(MsTaskPackage::getAState, "00");
                updateWrapper1.eq(MsTaskPackage::getMsTaskPackageId, msTaskPackage.getMsTaskPackageId());
                iMsTaskPackageService.update(updateWrapper1);
            }
            LocalLogDTO dto = new LocalLogDTO();
            dto.setLevel("INFO");
            dto.setMessage("计算是否全部配套完成:1.AO物料配套清单数量求和 以物料编码和AO分拣任务分组;2.AO物料配套信息中未配套和已配套的配套数量求和;3.通过物料编码相等且 清单中的配套数量大于信息的数量才计数");
            dto.setRequestParam(JSONObject.toJSONString(msTaskPackage) + JSONObject.toJSONString(msTaskAo));
            dto.setResponseParam("");
            dto.setMethod("AssortVerify");
            dto.setLoggerName("配套验证");
            dto.setIpAddress(request.getRemoteAddr());
            cemopService.saveLocalLog(dto);
        }catch(Exception e){
            LocalLogDTO dto = new LocalLogDTO();
            dto.setLevel("Error");
            dto.setMessage("计算是否全部配套完成:1.AO物料配套清单数量求和 以物料编码和AO分拣任务分组;2.AO物料配套信息中未配套和已配套的配套数量求和;3.通过物料编码相等且 清单中的配套数量大于信息的数量才计数");
            dto.setRequestParam(JSONObject.toJSONString(msTaskPackage) + JSONObject.toJSONString(msTaskAo));
            dto.setResponseParam(e.getMessage());
            dto.setMethod("AssortVerify");
            dto.setLoggerName("配套验证");
            dto.setIpAddress(request.getRemoteAddr());
            cemopService.saveLocalLog(dto);
        }
    }

    @Transactional
    public void standardAssort(MsTaskPackage msTaskPackage, MsTaskAo msTaskAo) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        //参数校验
        if (msTaskAo.getMsTaskAoId() == null || msTaskAo.getMsTaskAoId().isEmpty()) {
            throw  new IllegalArgumentException("参数为空");
        }
        try {
            //查询物料配套信息列表
            List<MsAoBzjBillVO> msAoBzjBillVOS = msAoBzjBillMapper.selectWithLackItemQty(msTaskAo.getMsTaskAoId());
            //遍历获取
            for (MsAoBzjBillVO msAoBzjBillVO : msAoBzjBillVOS) {
                handleStandardPiece(msAoBzjBillVO, msTaskPackage,msTaskAo);
            }
            LocalLogDTO dto = new LocalLogDTO();
            dto.setLevel("INFO");
            dto.setMessage("查询物料配套信息列表");
            dto.setRequestParam(JSONObject.toJSONString(msTaskPackage) + JSONObject.toJSONString(msTaskAo));
            dto.setResponseParam(JSONObject.toJSONString(msAoBzjBillVOS));
            dto.setMethod("standardAssort");
            dto.setLoggerName("标准件");
            dto.setIpAddress(request.getRemoteAddr());
            cemopService.saveLocalLog(dto);
        } catch (Exception e) {
            e.getMessage();
            LocalLogDTO dto = new LocalLogDTO();
            dto.setLevel("Error");
            dto.setMessage(e.getMessage());
            dto.setRequestParam(JSONObject.toJSONString(msTaskPackage) + JSONObject.toJSONString(msTaskAo));
            dto.setResponseParam(e.getMessage());
            dto.setMethod("standardAssort");
            dto.setLoggerName("标准件");
            dto.setIpAddress(request.getRemoteAddr());
            cemopService.saveLocalLog(dto);
        }
    }


    @Transactional
    public void handleStandardPiece(MsAoBzjBillVO msAoBzjBillVO, MsTaskPackage msTaskPackage, MsTaskAo msTaskAo) {
        if (msAoBzjBillVO == null || msTaskAo == null) {
            throw new IllegalArgumentException("参数不能为空");
        }
        int lackItemQty = msAoBzjBillVO.getLackItemQty();
        if (lackItemQty <= 0) {
            throw new IllegalArgumentException("标准件缺件数量不能为负数");
        }
        /**
         * 已配套数量
         */
        int alreadyPreAmount = 0;
        /**
         * 未配套数量
         */
        int noPreMatchAmount = lackItemQty;
        /**
         *  箱子已经分配的数量，标准件只会有一个箱子
         */
        int workbinAlreadyUseAmount = 0;
        /**
         * 查询台账数量
         */
        List<WmsItemInventoryVO> wmsItemInventoryVOS = msAoBzjBillMapper.selectWmsItenQty(msAoBzjBillVO, msTaskAo.getDepartCode());

        Map<String, Integer> workbinAlreadyUseAmountMap = new HashMap();

        for (WmsItemInventoryVO wmsItemInventoryVO : wmsItemInventoryVOS) {
            if (wmsItemInventoryVO == null) {
                continue;
            }
            String wmsItemInventoryId = wmsItemInventoryVO.getWmsItemInventoryId();
            //
            workbinAlreadyUseAmount = msAoBzjBillMapper.getWorkbinAlreadyUseAmount(wmsItemInventoryId);
            //  workbinAlreadyUseAmount = workbinAlreadyUseAmountMap.computeIfAbsent(wmsItemInventoryId, id -> msAoBzjBillMapper.getWorkbinAlreadyUseAmount(id));

            if (noPreMatchAmount == 0) {
                // 当前标准件未配套数量为0，说明配套完成
                break;
            }
            //判断当前台账是否已经分配完
            int currentOnhandQty = wmsItemInventoryVO.getCurrentOnhandQty();
            if (currentOnhandQty - workbinAlreadyUseAmount <= 0) {
                continue;
            }
            //配套数量是否小于等于当前库存
            int reqMatchQty;
            if (noPreMatchAmount <= currentOnhandQty - workbinAlreadyUseAmount) {

                /**
                 * 库存够用的情况
                 * alreadyPreAmount：已经配套的数量
                 * reqMatchQty：设置需要分配的数量
                 * noPreMatchAmount：未配套的数量
                 */
                alreadyPreAmount += noPreMatchAmount;
                reqMatchQty = noPreMatchAmount;
                noPreMatchAmount = 0;
            } else {

                /**
                 * 库存不够用
                 * 已经配套的数量
                 */
                alreadyPreAmount += currentOnhandQty - workbinAlreadyUseAmount;  //
                reqMatchQty = currentOnhandQty - workbinAlreadyUseAmount;
                noPreMatchAmount -= (currentOnhandQty - workbinAlreadyUseAmount);
            }
            //插入台账临时表及配套信息（结果表）
            msAoBzjBillMapper.insertSortItemInventoryTemp(msAoBzjBillVO, wmsItemInventoryVO, reqMatchQty);
            msAoBzjBillMapper.insertAoMatchInfo(msAoBzjBillVO, wmsItemInventoryVO, msTaskPackage,msTaskAo, reqMatchQty);

            if (noPreMatchAmount == lackItemQty) {
                /**
                 * 当前标准件未找到任何库存
                 */
                msAoBzjBillMapper.insertAoMatchInfoForNoInventory(msAoBzjBillVO,msTaskPackage, msTaskAo);
            }
        }
        /**
         * 更新标准件是否缺件
         */
        msAoBzjBillMapper.updateAoMatchInfoState(msAoBzjBillVO.getMsAoMatchBillId());
        msAoBzjBillMapper.updateAoMatchInfoStateForZeroMatchQty(msAoBzjBillVO.getMsAoMatchBillId());

    }


    //161-521 台账占用，库存预分配，占用缓存箱yyf
    @Transactional
    public void itemInventoryOccupy(MsTaskPackage msTaskPackage, MsTaskAo msTaskAo, MsAoMatchBill msAoMatchBill) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        try {
            boolean v_match_fin_sign = false;
            //未配套数量
            BigDecimal v_no_pre_match_amount = msAoMatchBill.getItemQty();
            //计算当前库存量，判断是否有库存
            String startPlaneNo = msTaskPackage.getStartPlaneNo();
            String departCode = msTaskAo.getDepartCode();
            String itemCode = msAoMatchBill.getItemCode();
            //当前库存数量-非离库数量-离库数量-虚拟配套占用数量
            int usableCount = wmsItemInventoryMapper.usableCount(startPlaneNo, departCode, msAoMatchBill);
            if (usableCount > 0) {
                //获取可用库存信息
                List<StockDTO> stockDTOS = wmsItemInventoryMapper.usableMaterial(startPlaneNo, departCode,msAoMatchBill);
                for (StockDTO stock : stockDTOS) {
                    //找到库存下的缓存箱及数量
                    List<usableWorkbinDTO> usableWorkbinDTOs = msWorkbinMaterialMapper.queryWorkbin(startPlaneNo, stock.getWmsItemInventoryId());
                    for (usableWorkbinDTO v_workbin_info : usableWorkbinDTOs) {
                        //工作包可用的物料数量
                        int v_workbin_already_use_amount = v_workbin_info.getItemQty() - v_workbin_info.getALREADYPREAMOUNTSUM();
                        if (v_workbin_already_use_amount <= 0) {
                            continue;
                        }
                        //compareTo(BigDecimal.ZERO)作用
                        int aaa = v_no_pre_match_amount.compareTo(BigDecimal.ZERO);
                        String matchInfoId = UUID.randomUUID().toString().replace("-", "");
                        //判断库存可用数量是否满足配套需求数量
                        if (v_workbin_already_use_amount >= v_no_pre_match_amount.compareTo(BigDecimal.ZERO)) {
                            //满足配套数量，直接写入数据并退出循环
                            System.out.print("准备写入ms_ao_match_info=========start======v_ao_task.ms_task_ao_id====" + msTaskAo.getMsTaskAoId());
                            MsSortItemInventoryTemp msSortItemInventoryTemp = new MsSortItemInventoryTemp();
                            msSortItemInventoryTemp.setMsSortItemInventoryTempId(ComUtil.getId());
                            msSortItemInventoryTemp.setWmsItemInventoryId(stock.getWmsItemInventoryId());
                            msSortItemInventoryTemp.setAmount(v_no_pre_match_amount);
                            msSortItemInventoryTemp.setWorkbinCode(v_workbin_info.getWorkbinCode());
                            msSortItemInventoryTemp.setCreationDate(LocalDateTime.now());
                            msSortItemInventoryTemp.setMsTaskAoId(msTaskAo.getMsTaskAoId());
                            msSortItemInventoryTemp.setAoCode(msTaskAo.getAoCode());
                            msSortItemInventoryTemp.setPackageCode(msTaskPackage.getPackageCode());
                            msSortItemInventoryTempMapper.insert(msSortItemInventoryTemp);
                            System.out.print("准备写入ms_ao_match_info=========msAoMatchBill==========" + msAoMatchBill);
                            msAoMatchInfoMapper.addMsAoMatchInfo(matchInfoId,v_workbin_info, msTaskAo, msTaskPackage, msAoMatchBill, stock, v_no_pre_match_amount);
                            v_match_fin_sign = true;
                            break;
                        } else if (v_workbin_already_use_amount < v_no_pre_match_amount.compareTo(BigDecimal.ZERO)) {
                            MsSortItemInventoryTemp msSortItemInventoryTemp = new MsSortItemInventoryTemp();
                            msSortItemInventoryTemp.setMsSortItemInventoryTempId(ComUtil.getId());
                            msSortItemInventoryTemp.setWmsItemInventoryId(stock.getWmsItemInventoryId());
                            msSortItemInventoryTemp.setAmount(BigDecimal.valueOf(v_workbin_already_use_amount));
                            msSortItemInventoryTemp.setItemCode(msAoMatchBill.getItemCode());
                            msSortItemInventoryTemp.setWorkbinCode(v_workbin_info.getWorkbinCode());
                            msSortItemInventoryTemp.setCreationDate(LocalDateTime.now());
                            msSortItemInventoryTemp.setMsTaskAoId(msTaskAo.getMsTaskAoId());
                            msSortItemInventoryTemp.setAoCode(msTaskAo.getAoCode());
                            msSortItemInventoryTemp.setPackageCode(msTaskPackage.getPackageCode());
                            msSortItemInventoryTempMapper.insert(msSortItemInventoryTemp);
                            msAoMatchInfoMapper.addMsAoMatchInfo(matchInfoId,v_workbin_info, msTaskAo, msTaskPackage, msAoMatchBill, stock, BigDecimal.valueOf(v_workbin_already_use_amount));
                            //已配套数量
                            v_no_pre_match_amount = v_no_pre_match_amount.subtract(BigDecimal.valueOf(v_workbin_already_use_amount));
                        }
                    }
                    if (v_match_fin_sign == true) {
                        break;
                    }
                }
            } else if (usableCount == 0) {
                String matchInfoId = UUID.randomUUID().toString().replace("-", "");
                msAoMatchInfoMapper.addUsableMsAoMatchInfo(matchInfoId,msTaskAo, msTaskPackage, msAoMatchBill);
            }
            LocalLogDTO dto = new LocalLogDTO();
            dto.setLevel("INFO");
            dto.setMessage("当前库存数量-非离库数量-离库数量-虚拟配套占用数量");
            dto.setRequestParam(JSONObject.toJSONString(msTaskPackage) + JSONObject.toJSONString(msTaskAo) + JSONObject.toJSONString(msAoMatchBill));
            dto.setResponseParam("");
            dto.setMethod("itemInventoryOccupy");
            dto.setLoggerName("台账占用，库存预分配，占用缓存箱");
            dto.setIpAddress(request.getRemoteAddr());
            cemopService.saveLocalLog(dto);
        } catch (Exception e) {
            LocalLogDTO dto = new LocalLogDTO();
            dto.setLevel("Error");
            dto.setMessage("当前库存数量-非离库数量-离库数量-虚拟配套占用数量");
            dto.setRequestParam(JSONObject.toJSONString(msTaskPackage) + JSONObject.toJSONString(msTaskAo) + JSONObject.toJSONString(msAoMatchBill));
            dto.setResponseParam(e.getMessage());
            dto.setMethod("itemInventoryOccupy");
            dto.setLoggerName("台账占用，库存预分配，占用缓存箱");
            dto.setIpAddress(request.getRemoteAddr());
            cemopService.saveLocalLog(dto);
        }
    }

    @Transactional
    public void artChange(MsTaskPackage msTaskPackage, MsTaskAo msTaskAo, MsAoMatchBill msAoMatchBill) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        try {
            //如果工作包经过工艺更改，删除即拆包，旧物料在macthInfo表的状态修改为工艺更改状态。
            //并且标注出修改数量。方便拆包获取。
            String isArtChange = msAoMatchBill.getIsArtChange();
            String artChangeType = msAoMatchBill.getArtChangeType();
            //判断是否工艺更改和工艺更改类型A 新增 D 删除  U 修改
            if ("Y".equals(isArtChange) && ("D".equals(artChangeType) || "U".equals(artChangeType))) {
                //通过物料编码、是否分拣、AO物料配套清单ID查出AO物料配套清单
                LambdaQueryWrapper<MsAoMatchInfo> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.eq(MsAoMatchInfo::getMsAoMatchBillId, msAoMatchBill.getMsAoMatchBillId());
                queryWrapper.eq(MsAoMatchInfo::getItemCode, msAoMatchBill.getItemCode());
                queryWrapper.eq(MsAoMatchInfo::getIsSort, "Y");
                List<MsAoMatchInfo> list = imsAoMatchInfoService.list(queryWrapper);
                //修改AO物料配套清单  是否工艺更改 是 工艺更改类型 D||Y 数量 是否工艺更改归零 D删除就是 U修改就不是
                for (MsAoMatchInfo msAoMatchInfo : list) {
                    UpdateWrapper<MsAoMatchInfo> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.set("IS_ART_CHANGE", "Y");
                    updateWrapper.set("ART_CHANGE_TYPE", isArtChange);
                    updateWrapper.set("ITEM_QTY", msAoMatchBill.getArtChangeNum());
                    String isChangeZero = "N";
                    if (artChangeType == "D") {
                        isChangeZero = "Y";
                    }
                    updateWrapper.set("IS_CHANGE_ZERO", isChangeZero);
                    updateWrapper.eq("MS_AO_MATCH_INFO_ID", msAoMatchBill.getMsAoMatchInfoId());
                }
                LocalLogDTO dto = new LocalLogDTO();
                dto.setLevel("INFO");
                dto.setMessage("判断是否工艺更改和工艺更改类型A新增 D删除  U修改、通过物料编码、是否分拣、AO物料配套清单ID查出AO物料配套清单、修改AO物料配套清单  是否工艺更改 是 工艺更改类型 D||Y 数量 是否工艺更改归零 D删除就是 U修改就不是");
                dto.setRequestParam(JSONObject.toJSONString(msTaskPackage) + JSONObject.toJSONString(msTaskAo) + JSONObject.toJSONString(msAoMatchBill));
                dto.setResponseParam(JSONObject.toJSONString(list));
                dto.setMethod("artChange");
                dto.setLoggerName("工艺更改");
                dto.setIpAddress(request.getRemoteAddr());
                cemopService.saveLocalLog(dto);
            }
        } catch (Exception e) {
            LocalLogDTO dto = new LocalLogDTO();
            dto.setLevel("Error");
            dto.setMessage("判断是否工艺更改和工艺更改类型A新增 D删除  U修改、通过物料编码、是否分拣、AO物料配套清单ID查出AO物料配套清单、修改AO物料配套清单  是否工艺更改 是 工艺更改类型 D||Y 数量 是否工艺更改归零 D删除就是 U修改就不是");
            dto.setRequestParam(JSONObject.toJSONString(msTaskPackage) + JSONObject.toJSONString(msTaskAo) + JSONObject.toJSONString(msAoMatchBill));
            dto.setResponseParam(e.getMessage());
            dto.setMethod("artChange");
            dto.setLoggerName("工艺更改");
            dto.setIpAddress(request.getRemoteAddr());
            cemopService.saveLocalLog(dto);
        }
    }

}
